package org.bee.transaction;

import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;

/**
 * 编程式事务
 */
public class MyTransaction implements Transaction {
    private PlatformTransactionManager transactionManager;
    private TransactionStatus txStatus;
    private TransactionDefinition txDefinition;
    public void commit() {
        this.transactionManager.commit(txStatus);

    }
    public void rollback() {
        this.transactionManager.rollback(txStatus);
    }
    public void setTxManager(PlatformTransactionManager transactionManager) {
        this.transactionManager = transactionManager;

    }
    public void setTransactionDefinition(TransactionDefinition txDefinition) {
        this.txDefinition = txDefinition;
    }
    public void begin() {
        txStatus = transactionManager.getTransaction(txDefinition);
    }
}
